package MediaOnline.GUI;

import MediaOnline.Adapter.VideoAdapter;
import MediaOnline.Data.filmDetail;
import MediaOnline.Data.videoData;
import MediaOnline.WebService.GetFilmByID;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.GridView;

public class actFilmMoi extends Activity {
	static VideoAdapter adpListVideo;
	static GridView gVideoList1;
	public static String status="status";
	int FilmCatID=-1;
	public static Context ctx;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.filmmoi);
		gVideoList1 = (GridView) findViewById(R.id.gVideoList1);
		ctx = actFilmMoi.this;
		//Tao cac adapter
		adpListVideo  = new VideoAdapter(getApplicationContext());
		//Load list movie tren server 
		adpListVideo.getListVideo(actFilmMoi.this,FilmCatID);
		//Kiem tra do phan giai man hinh
		Display display = getWindowManager().getDefaultDisplay();
		int width = (int) (display.getWidth());
		int Cot = width/500;
		gVideoList1.setNumColumns(Cot);
		
		gVideoList1.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> a, View v, int i,
					long l) {
				// TODO Auto-generated method stub
				//index = i;
				filmDetail.FilmID=videoData.lstVideoID.get(i);
				filmDetail.Url = videoData.lstVideoLink.get(i);
				startActivity(new Intent(actFilmMoi.this, actFilmDetailInfo2.class));
				GetFilmByID g = new GetFilmByID(actFilmMoi.this);
				g.get();			
			}
		});
		
		//Xu li su kien longclick
		gVideoList1.setOnItemLongClickListener(new OnItemLongClickListener() {

			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					int i, long arg3) {
				// TODO Auto-generated method stub
				//index = i;
				Intent intent = new Intent(actFilmMoi.this, Nahi_MediaActivity.class);
				Bundle newBundle = new Bundle();
				newBundle.putString("Link", videoData.lstVideoLink.get(i));
				intent.putExtras(newBundle);
				startActivity(intent);
				return false;
			}
		});
		

		
	}
	
	public static void ViewList(){
		gVideoList1.setAdapter(adpListVideo);
	}
	
	//Xu ly khi chon the loai phim
	public static void LoadFilmByCat(int FilmCatID){
		adpListVideo  = new VideoAdapter(ctx);
		//Load list movie tren server 
		adpListVideo.getListVideo(ctx,FilmCatID);
	}
	
	
	//Update film moi sau khi chon the loai phim
	public static void UpdateListFilm(){
		gVideoList1.setAdapter(adpListVideo);
	}
	
	
	
}
